<template>
	<view v-if="show" class="a_mask">
		<view class="a_box">
			<view class="a_head">{{title}}</view>
			<view class="a_input">
				<textarea v-if="type == 'textarea'" @blur="bindTextAreaBlur" :value="content" :placeholder="placeholder" />
				<input v-else @blur="bindTextAreaBlur" :value="content" :placeholder="placeholder"/>
			</view>
			<view class="a_btn">
				<button @click="cancel" :style="{color:cancelColor}">{{cancelText}}</button>
				<button @click="confirm" :style="{color:confirmColor}">{{confirmText}}</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	props:{
		show: {
			type: Boolean,
			default: false
		},
		title:{
			type:String,
			default:'提示'
		},
		placeholder:{
			type:String,
			default:'请点击输入'
		},
		name:{
			type:String,
			default:'text'
		},
		type:{
			type:String,
			default:'text'
		},
		value:{
			type:String,
			default:''
		},
		cancelColor:{
			type:String,
			default:'#999999'
		},
		confirmColor:{
			type:String,
			default:'#333333'
		},
		cancelText:{
			type:String,
			default:'取消'
		},
		confirmText:{
			type:String,
			default:'确定'
		},
	},
	data(){
		return {
			content: ''
		}
	},
	created(){
		this.content = this.value;
	},
	methods: {
		bindTextAreaBlur(e){
			this.content = e.detail.value;
		},
		confirm(){
			this.$emit('confirm', this.content)
		},
		cancel(){
			this.$emit('cancel')
		}
	}
}
</script>

<style lang="scss" scoped>
.a_mask{
	position: fixed;
	z-index: 99999;
	background-color: rgba(0,0,0,0.5);
	top: 0;
	left: 0;
	bottom: 0;
	right: 0;
	.a_box{
		width: 500upx;
		overflow: hidden;
		
		background-color: #fff;
		border-radius: 10upx;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%,-50%);
		
		.a_head{
			text-align: center;
			font-size: 30upx;
			line-height: 88upx;
		}
		.a_input{
			padding: 0 20upx 30upx;
			font-size: 28upx;
			input{
				text-align: center;
			}
			textarea{
				width: 100%;
				padding: 10upx;
				height: 160upx;
				font-size: 28upx;
				background: #F0F0F0;
				border-radius: 10upx;
				box-sizing: border-box;
			}
		}
		.a_btn{
			text-align: center;
			font-size: 30upx;
			line-height: 88upx;
			display: flex;
			justify-content: space-between;
			border-top: 2upx solid #f5f5f5;
			button{
				width: 50%;
				background-color: #fff;
				font-size: 30upx;
				border-radius: 0upx;
				padding: 0;
				&::after{
					border:none
				}
				&:first-child{
					border-right: 2upx solid #f5f5f5;
					color: #999999;
					box-sizing: border-box;
				}
				&:last-child{
					color: #333;
				}
			}
			
		}
	}
}
</style>
